package org.cjlm.ui.skin; 
 
import javax.swing.*;
import java.awt.*;
import java.util.HashMap;
import java.util.Map; 
 
public class SkinManager {
    private static final Map<String, SkinConfig> skinConfigs = new HashMap<>();
    private static String currentSkin = "default";
    
    static {
        // 注册预定义皮肤
        registerSkin("xp", new SkinConfig(
            "Windows XP",
            "com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel"
        ));
        
        registerSkin("macos", new SkinConfig(
            "macOS",
            "com.formdev.flatlaf.themes.FlatMacLightLaf"
        ));
        
        registerSkin("nimbus", new SkinConfig(
            "Nimbus",
            "javax.swing.plaf.nimbus.NimbusLookAndFeel"
        ));
        
        registerSkin("flatdark", new SkinConfig(
            "Flat Dark",
            "com.formdev.flatlaf.themes.FlatMacDarkLaf"
        ));
    }
    
    public static void registerSkin(String id, SkinConfig config) {
        skinConfigs.put(id,  config);
    }
    
    public static void applySkin(String skinId) {
        try {
            SkinConfig config = skinConfigs.get(skinId); 
            if (config == null) config = skinConfigs.get("macos");
            
            UIManager.setLookAndFeel(config.getLookAndFeel()); 
            currentSkin = skinId;

        } catch (Exception e) {
            JOptionPane.showMessageDialog(null,  "皮肤切换失败: " + e.getMessage());
            e.printStackTrace();
        }
    }
    
    public static String getCurrentSkin() {
        return currentSkin;
    }
    
    public static class SkinConfig {
        private final String name;
        private final String lookAndFeel;

        public SkinConfig(String name, String lookAndFeel) {
            this.name  = name;
            this.lookAndFeel  = lookAndFeel;
        }
        
        // Getters 
        public String getLookAndFeel() { return lookAndFeel; }
    }
}